<?php
namespace app\manage\validate;
use think\Validate;
class GoodsValidate extends Validate
{
     protected $rule = [
        'goods_name' =>  'require|lizhiliUnique:goods|length:3,200',
        'markte_price'=>'require',
       'money'=>'require',
        'goods_desc'=>'require',


    ];
	 protected $message  =   [
        'goods_name.require' => '商品名称必须填写', 
        'goods_name.unique'     => '当前商品名称已经存在，不能重复！',
        'goods_name.length'=>'商品名称在3-60个字符之间！',
        'markte_price.require' => '市场价格必须填写',
       'money.require' => '本店价格必须填写',
        'goods_desc.require' => '产品描述必须填写', 

    ];
	protected $scene = [
        'edit'  =>  [
		        'goods_name' =>  'require|length:3,60',
		        'markte_price'=>'require',
		        'money'=>'require',
		        'goods_desc'=>'require',

			],
    ];
    // 自定义验证规则
    protected function lizhiliUnique($value, $rule, $data=[],$field='',$desc='')
    {
        $where = [['delete_time','=',Null],[$field,'=',$value]];
        $str='\\app\\model\\'.ucfirst($rule).'Model';
        $count = (new $str())->where($where)->count();
        if($count){
            return false;
        }
        return true;
    }
}

